package bravo.xc.com.xc_bravo_android.http;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

import static bravo.xc.com.xc_bravo_android.beans.ApiBeans.BASE_URL;

/**
 * CREATED BY YANK
 * DATE : 2017/10/30
 * MAIL : YANK.TENYOND@GMAIL.COM
 * FUNCTION :
 */

public class HttpSingleton {

    private OkHttpClient.Builder builder;
    private int CONNECT_TIME_OUTT = 15000;
    private Retrofit retrofit;
    public UserOperationService service;

    /**
     * private the constructor
     */
    private HttpSingleton(){
        builder = new OkHttpClient.Builder();
        builder.connectTimeout(CONNECT_TIME_OUTT, TimeUnit.MILLISECONDS);

        retrofit = new Retrofit.Builder()
                .client(builder.build())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(BASE_URL)
                .build();
        service = retrofit.create(UserOperationService.class);
    }

    /**
     * 内部静态类实现单例
     */
    private static class SingletonHolder {
        private static final HttpSingleton INSTANCE = new HttpSingleton();
    }

    public static HttpSingleton getInstance() {
        return SingletonHolder.INSTANCE;
    }
}
